package com.kucai.yifaqapp.ui.fragment;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.TextView;

import com.bigkoo.pickerview.TimePickerView;
import com.kucai.yifaqapp.R;
import com.kucai.yifaqapp.global.HttpAdress;
import com.kucai.yifaqapp.global.Info;
import com.kucai.yifaqapp.model.CustomObserver;
import com.kucai.yifaqapp.model.network.HttpJsonUtils;
import com.kucai.yifaqapp.model.network.entity.res.ResUserTable;
import com.kucai.yifaqapp.util.DateSelector;
import com.kucai.yifaqapp.util.PriceUtils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.TimeZone;

import butterknife.BindView;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by admin on 2018/12/20.
 */

public class RecommentFragmentfour extends BaseFragmentSimple {
    @BindView(R.id.usertext1)
    TextView usertext1;
    @BindView(R.id.usertext2)
    TextView usertext2;
    @BindView(R.id.usertext3)
    TextView usertext3;
    @BindView(R.id.usertext4)
    TextView usertext4;
    @BindView(R.id.usertext5)
    TextView usertext5;
    @BindView(R.id.usertext6)
    TextView usertext6;
    @BindView(R.id.usertext7)
    TextView usertext7;
    @BindView(R.id.usertext8)
    TextView usertext8;
    @BindView(R.id.usertext9)
    TextView usertext9;
    @BindView(R.id.usertext10)
    TextView usertext10;
    @BindView(R.id.usertext11)
    TextView usertext11;
    @BindView(R.id.usertext12)
    TextView usertext12;
    @BindView(R.id.usertext13)
    TextView usertext13;
    @BindView(R.id.usertext14)
    TextView usertext14;
    @BindView(R.id.databt)
    TextView databt;
    private String datatime;
    private String endetime;
    private static final List<String> optionsItems = new ArrayList<>();//游戏弹框
    private TimePickerView pvTime;

    @Override
    protected int setContentView() {
        return R.layout.fragment_recomment_04;
    }

    @Override
    protected void ChangeSkin() {

    }

    @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        timepopset();
        pvTime = DateSelector.getPvDatePreDay(getContext(), new TimePickerView.OnTimeSelectListener() {
            @Override
            public void onTimeSelect(Date date, View v) {
                databt.setText(DateSelector.getDateString(date));
                datatime = DateSelector.getDateString2(date);
                getdata();
            }
        });
        databt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pvTime.show();
            }
        });
        getdata();
    }

    private void getdata() {
        HttpJsonUtils.getHttpApiInstance()
                .getusertable(HttpAdress.getuseAdress() + "api/m/pc/bet/getUsersReportTotal", Info.user.token, datatime, endetime)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new CustomObserver<ResUserTable>(this) {
                    @Override
                    protected void onSubscribeCustom(Disposable disposable) {
                    }

                    @Override
                    protected void onErrorCustom(Throwable e) {

                    }

                    @Override
                    protected void onCustomNext(ResUserTable resCode) {
                        if (resCode.code == 0 && resCode.data != null) {
/**
 * "reg_num": 1,//新增人数
 “all_num”:1，//团队总人数
 "drawing_num": 0,//提款人数
 "recharges_num": 0,//充值人数
 "bet_count": "31",//投注数
 "bet_money": "310.00",//投注金额11
 "bet_amount": "150.00",//盈利投注金额11
 "fact_bet_bunko": "-12.85",//会员实际输赢
 "bet_bunko": "-12.85",//会员输赢11
 "fact_return_amount": "0.00",//实际退水
 "activity_money": "0.00",//活动金额11
 "handling_fee": "0.00",//手续费11
 "drawing_money": "0.00",//提款金额11
 "recharges_money": "0.00",//充值金额11

 */
                            usertext1.setText(resCode.data.reg_num + "");
                            usertext2.setText(resCode.data.all_num + "");
                            usertext3.setText(resCode.data.drawing_num + "");
                            usertext4.setText(resCode.data.recharges_money + "");
                            usertext5.setText(resCode.data.bet_count + "");
                            usertext6.setText(resCode.data.bet_money + "");
                            PriceUtils.format(usertext6);
                            usertext7.setText(resCode.data.bet_amount + "");
                            PriceUtils.format(usertext7);
                            usertext8.setText(resCode.data.fact_bet_bunko + "");
                            usertext9.setText(resCode.data.bet_bunko + "");
                            PriceUtils.format(usertext9);
                            usertext10.setText(resCode.data.fact_return_amount + "");
                            usertext11.setText(resCode.data.activity_money + "");
                            usertext12.setText(resCode.data.handling_fee + "");
                            usertext13.setText(resCode.data.drawing_money + "");
                            usertext14.setText(resCode.data.recharges_money + "");
                            PriceUtils.format(usertext11);
                            PriceUtils.format(usertext12);
                            PriceUtils.format(usertext13);
                            PriceUtils.format(usertext14);

                        }

                    }
                });
    }

    private void timepopset() {
        //获取当前时间
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
        Date curDate = new Date(System.currentTimeMillis());
        String str = formatter.format(curDate);

        datatime = str;
        endetime = str;
        databt.setText(str);
    }
}
